//经验推介
function onHjqcSuoActionRenderer(e) {
    var record = e.value;
    if (record != null) {
        var arr = record.split("@");
        var announce = arr[0];
        var isowner = arr[1];
    }
    var s = "";
    s += '&nbsp;<a class="mini-button mini-button-info"  onclick="checkJytjInfo()"  >&nbsp;&nbsp;查看&nbsp;&nbsp;</a>&nbsp';
    if (record == null || announce == "0") {
        s += '&nbsp;<a class="mini-button mini-button-primary"  onclick="editJytjInfo()"  >&nbsp;&nbsp;编辑&nbsp;&nbsp;</a>&nbsp';
        s += '&nbsp;<a class="mini-button mini-button-warning"  onclick="setfabuState(1)"  >&nbsp;&nbsp;发布&nbsp;&nbsp;</a>&nbsp';
        s += '&nbsp;<a class="mini-button mini-button-danger"  onclick="delJytjInfo(22)"  >&nbsp;&nbsp;删除&nbsp;&nbsp;</a>&nbsp';
    } else if (announce == "1" && isowner == '1') {
        s += '&nbsp;<a class="mini-button mini-button-warning"  onclick="setfabuState(0)"  >&nbsp;&nbsp;取消发布&nbsp;&nbsp;</a>&nbsp';
    }
    s += '&nbsp;<a class="mini-button mini-button-success"  onclick="downloadFilesZip(22)"  >&nbsp;&nbsp;下载&nbsp;&nbsp;</a>&nbsp';
    return s;
}

//新增
function addJytjInfo() {
    var data = {stat: 1};
    if (data) {
        showJytjInfoWindow(data);
    }
}

//修改
function editJytjInfo() {
    var row = grid.getSelected();
    if (row) {
        $.ajax({
            url: encodeURI("/azbj/abzlxxgl/jytjInfoManage/checkIfOwnerPublish/" + row.id),
            cache: false,
            success: function (result) {
                if (result.code == 1) {
                    showJytjInfoWindow(row);
                } else {
                    mini.alert("非本人发布的内容无法进行编辑");
                }
            }
        });

    } else {
        mini.alert("请至少选择一条数据！");
    }
}

//查看
function checkJytjInfo() {
    var row = grid.getSelected();
    if (row) {
        commonEdit("/azbj/abzlxxgl/jytjInfoManage/view?ischeck=1", "经验推介", row, "50%", "78%", true, true, true, callback);

        function callback() {
            grid.reload();
        }
    } else {
        mini.alert("请至少选择一条数据！");
    }
}

//新增修改跳转页面
function showJytjInfoWindow(row) {
    commonEdit("/azbj/abzlxxgl/jytjInfoManage/view", "经验推介", row, "50%", "82%", true, true, true, callback);

    function callback() {
        grid.reload();
    }
}

//删除
function delJytjInfo(taskId) {
    var row = grid.getSelected();
    if (row) {
        $.ajax({
            url: encodeURI("/azbj/abzlxxgl/jytjInfoManage/checkIfOwnerPublish/" + row.id),
            cache: false,
            success: function (result) {
                if (result.code == 1) {
                    commonRemove("/azbj/abzlxxgl/jytjInfoManage/delete?id=" + row.id + "&taskId=" + taskId, row, {_method: "delete"}, callback);

                    function callback() {
                        grid.reload();
                    }
                } else {
                    mini.alert("非本人发布的内容无法进行删除");
                }
            }
        });
    } else {
        mini.alert("请至少选中一条记录");
    }
}

//下载
function downloadFilesZip(taskId) {
    var row = grid.getSelected();
    if (row) {
        $.ajax({
            url: encodeURI("/azbj/abzlxxgl/zcwjInfoManage/ifFileExist?id=" + row.id + "&taskId=" + taskId),
            cache: false,
            success: function (result) {
                if (result.code == 1) {
                    top.location.href = encodeURI("/azbj/abzlxxgl/zcwjInfoManage/downloadFilesZip?id=" + row.id + "&taskId=" + taskId);
                } else {
                    mini.alert("没有可下载的文件");
                }
            }
        });
    } else {
        mini.alert("请至少选中一条记录");
    }
}

//格式化日期函数
function onDateRenderer(e) {
    var date = new Date(e.value);
    var Y = date.getFullYear() + '-';
    var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
    var D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' ';
    var h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
    var m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
    var s = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());
    var formatTime = Y + M + D + h + m + s;
    return formatTime;
}

//发布范围转换
function onGetFbfwTypeName(e) {
    var types = e.value;
    var typeValues = types.split(',')
    var typeName = '';
    for (var i = 0; i < typeValues.length; i++) {
        if (i === typeValues.length - 1) {
            typeName += getTypeName(typeValues[i])
        } else {
            typeName += getTypeName(typeValues[i]) + ','
        }
    }
    return typeName;
}

function getTypeName(type) {
    if (type == '6') {
        return "省司法厅";
    } else if (type == '7') {
        return "地市司法局";
    } else if (type == '8') {
        return "区县司法局";
    } else if (type == '3') {
        return "基层司法所";
    } else if (type == '9') {
        return "监狱局";
    } else if (type == '1') {
        return "监所";
    } else {
        return "其他";
    }
}

//设置发布取消发布
function setfabuState(stateValue) {
    var row = grid.getSelected();
    if (row) {
        mini.confirm("确定操作选中记录？",
            "确定？",
            function (action) {
                if (action == "ok") {
                    $.ajax({
                        url: encodeURI("/azbj/abzlxxgl/jytjInfoManage/setfabuState?id=" + row.id + "&stateValue=" + stateValue + "&account=" + row.createUser),
                        cache: false,
                        success: function (result) {
                            if (result.code == 1) {
                                mini.alert("操作成功");
                            } else if (result.code == 4000) {
                                mini.alert("非本人发布,不可操作");
                            } else {
                                mini.alert("操作失败");
                            }
                            grid.reload();
                        }
                    });
                }
            });
    } else {
        mini.alert("请选中一条记录");
    }
}